<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">	
		#my-table {
			border-collapse: collapse;
			width: 400px;
		}
		#my-table td{
			border: 1px solid #ccc;
		}
	</style>
</head>
<body>
	<table id="my-table">
		<tr>
			<td>line1</td>
			<td>line2</td>
			<td>line4</td>
		</tr>
		<tr>
			<td>line1</td>
			<td>line2</td>
			<td>line4</td>
		</tr>
	</table>
	<button onclick="copyData(this)">Copy</button>
	<script type="text/javascript">
		function copyData (btnObj) {
			var container = document.querySelector("#my-table");
			// var  d = tbl.createRange();
			if (window.getSelection) { //chrome,firefox,opera
		        var range=window.getSelection().getRangeAt(1);
		        // var container = document_createElement_x_x_x_x('div');
		        container.a(range.cloneContents());
		        // return container.innerHTML;
		        //return window.getSelection(); //只复制文本
		        console.log(window.getSelection())
		    }
		    else if (document.getSelection) { //其他
		        var range=window.getSelection().getRangeAt(0);
		        var container = document_createElement_x_x_x_x('div');
		        container.a(range.cloneContents());
		        // return container.innerHTML;
		        //return document.getSelection(); //只复制文本
		    }
		    else if (document.selection) { //IE特有的
		        var d = document.selection.createRange().htmlText;
		        //return document.selection.createRange().text; //只复制文本
		    }
		}
	</script>
</body>
</html>